package com.example.WebSocketDemo.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.WebSocketDemo.bean.RecentMessage;
import com.example.WebSocketDemo.mapper.RecentMessageMapper;
import com.example.WebSocketDemo.mapper.UserMapper;
import com.example.WebSocketDemo.service.RecentMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("recentMessageImpl")
public class RecentMessageServiceImpl  implements RecentMessageService {
    @Autowired
    private RecentMessageMapper recentMessageMapper;
    @Override
    public List<RecentMessage> getRecentMessageByUserName(String username) {
        return recentMessageMapper.getRecentMessageByUserName(username);
    }

    @Override
    public void updateRecentMessage(String message,String from,String to) {
        JSONObject jsonObject = JSON.parseObject(message);
        String textMessage = jsonObject.getString("message");
       recentMessageMapper.updateRecentMessage(textMessage,from,to);
    }

    @Override
    public void updateUnreadMessageCount(String from, String to) {
        //System.out.println(from+to);
        recentMessageMapper.updateUnreadMessageCount(from,to);
    }
}
